/*
数据结构 解题报告：
http://git.oschina.net/et0662/sznoi-Data_Structure
*/
#include<stdio.h>

typedef struct __NODE
{
	int xs;
	int zs;
	struct __NODE * next;
}Node, * Link;

void insert(Link y, Node* node)
{
	Node* p;
	p=y;
	while(p->next)
	{
		if(p->next->zs == node->zs){
			p->next->xs = p->next->xs + node->xs;
			return;
		}
		else if(p->next->zs > node->zs)
			p=p->next;
		else
			break;

	}
	node->next=p->next;
	p->next=node;
}

void print(Link y)
{
	Node *p;
	int flag=0;
	p=y;
	while(p->next)
	{
		p=p->next;
		if(p->xs){
			printf("%d %d ",p->xs,p->zs);
			flag=1;
		}
	}
	if(flag==0)
		printf("0");
}

Link add(Link y1, Link y2)
{
	Link y;
	Node *p1, *p2, *p3,* p;
	y=new Node;
	y->next=NULL;

	p1=y1;
	p2=y2;
	p3=y;

	while((p1->next) && (p2->next))
	{
		p=new Node;
		p->next=NULL;
		if(p1->next->zs == p2->next->zs)
		{
			p->zs=p1->next->zs;
			p->xs=p1->next->xs + p2->next->xs;
			p1=p1->next;
			p2=p2->next;
		}
		else if(p1->next->zs > p2->next->zs)
		{
			p->zs=p1->next->zs;
			p->xs=p1->next->xs;
			p1=p1->next;
		}
		else
		{
			p->zs=p2->next->zs;
			p->xs=p2->next->xs;
			p2=p2->next;
		}
		p3->next=p;
		p3=p3->next;
	}

	while(p1->next)
	{
		p=new Node;
		p->next=NULL;
		p->zs=p1->next->zs;
		p->xs=p1->next->xs;
		p1=p1->next;
		p3->next=p;
		p3=p3->next;
	}

	while(p2->next)
	{
		p=new Node;
		p->next=NULL;
		p->zs=p2->next->zs;
		p->xs=p2->next->xs;
		p2=p2->next;
		p3->next=p;
		p3=p3->next;
	}
	return y;
}

int main(void)
{
	Link y1,y2,y3;
	Node* p;
	int t1,t2;
	char c;
	y1=new Node;
	y1->next=NULL;
	y2=new Node;
	y2->next=NULL;

	while(true)
	{
		scanf("%d %d%c",&t1,&t2,&c);
		p=new Node;
		p->next=NULL;
		p->xs=t1;
		p->zs=t2;
		insert(y1,p);
		if((c=='\n')||(c=='\r'))
			break;
	}

	while(true)
	{
		scanf("%d %d%c",&t1,&t2,&c);
		p=new Node;
		p->next=NULL;
		p->xs=t1;
		p->zs=t2;
		insert(y2,p);
		if((c=='\n')||(c=='\r'))
			break;
	}
	
	y3=add(y1,y2);
	print(y3);
	/*
	delete(y1);
	delete(y2);
	delete(y3);
	*/
	return 0;
}
